﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BUS.DAL;

namespace BUS
{
    public class SanPhamBUS
    {
        #region Properties
        public int ID { get; set; }
        public string MaSanPham { get; set; }
        public string TenSanPham { get; set; }

        #region LoaiSanPham
        
        public LoaiSanPhamBUS LoaiSanPham { get; set; }
        public string TenLoaiSanPham
        {
            get
            {
                return LoaiSanPham == null ? String.Empty : LoaiSanPham.TenLoai;
            }
        }
        #endregion

        public string MoTa { get; set; }

        #region Gia
        private decimal gia;
        public decimal Gia
        {
            get { return gia; }
            set { gia = value; }
        }
        public string strGia
        {
            get
            {
                return SoTon == 0 ? "Hết hàng" : String.Format("{0:0,0 triệu VNĐ}", gia/1000000);
            }
        }
        #endregion

        public string Anh { get; set; }

        public int SoLuong { get; set; }

        public string strSoLuong
        {
            get
            {
                return SoLuong.ToString();
            }

        }

        public string BaoHanh { get; set; }

        public int SoTon { get; set; }
        public string strSoTon
        {
            get
            {
                return SoTon.ToString();
            }
        }
        #endregion



        public static List<SanPhamBUS> GetAll()
        {
            return SanPhamDAL.GetAll();
        }

        public static List<SanPhamBUS> GetByLoaiSanPham(int idCate)
        {
            return SanPhamDAL.GetByCate(idCate);
        }

        public static SanPhamBUS GetSanphamByID(int id)
        {
            return SanPhamDAL.GetSanPhamByID(id);
        }


        public void Update()
        {
            SanPhamDAL.Update(this);
        }

        public void Delete()
        {                        
            SanPhamDAL.Delete(this);
        }
        public static List<SanPhamBUS> GetTopProducts()
        {
            return SanPhamDAL.GetTopProducts();
        }
        #region Dang
        public void Insert()
        {
            ID = SanPhamDAL.Insert(this); 
        }
        #endregion
    }
}
